package com.fzhucc.modules.sciPersonnelInfo.controller;

import com.fzhucc.annotation.Log;
import com.fzhucc.modules.sciPersonnelInfo.domain.dto.SciExpertOfflineConfigEditDto;
import com.fzhucc.modules.sciPersonnelInfo.domain.dto.SciExpertOfflineConfigQueryCriteria;
import com.fzhucc.modules.sciPersonnelInfo.service.SciExpertOfflineConfigService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
* @author yyg
* @date 2023-10-20
**/
@RestController
@RequiredArgsConstructor
@Api(tags = "劳模:线下辅导配置")
@RequestMapping("/api/sciExpertOfflineConfig")
public class SciExpertOfflineConfigController {

    private final SciExpertOfflineConfigService expertOfflineConfigService;

    @Log("导出数据")
    @ApiOperation("导出数据")
    @GetMapping(value = "/download")
    @PreAuthorize("@el.check('sciExpertOfflineConfig:list')")
    public void exportExpertOfflineConfig(HttpServletResponse response, SciExpertOfflineConfigQueryCriteria criteria) throws IOException {
        expertOfflineConfigService.download(expertOfflineConfigService.queryAll(criteria), response);
    }

    @GetMapping
    @Log("查询专家线下辅导配置")
    @ApiOperation("查询专家线下辅导配置")
    @PreAuthorize("@el.check('sciExpertOfflineConfig:list')")
    public ResponseEntity<Object> queryExpertOfflineConfig(SciExpertOfflineConfigQueryCriteria criteria, Pageable pageable){
        return new ResponseEntity<>(expertOfflineConfigService.queryAll(criteria,pageable),HttpStatus.OK);
    }

    @DeleteMapping
    @Log("删除专家线下辅导配置")
    @ApiOperation("删除专家线下辅导配置")
    @PreAuthorize("@el.check('sciExpertOfflineConfig:del')")
    public ResponseEntity<Object> deleteExpertOfflineConfig(@RequestBody Integer[] ids) {
        expertOfflineConfigService.deleteAll(ids);
        return new ResponseEntity<>(HttpStatus.OK);
    }

    @PostMapping(value = "/saveList")
    @Log("专家线下辅导配置操作")
    @ApiOperation("专家线下辅导配置操作")
    public ResponseEntity<Object> editExpertConsultationConfig(@Validated @RequestBody SciExpertOfflineConfigEditDto resources){
        return new ResponseEntity<>(expertOfflineConfigService.saveList(resources),HttpStatus.NO_CONTENT);
    }
}